package cn.snow.boot.swagger.controller;

import cn.snow.boot.swagger.entity.User;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * @author liuwanxiang
 * @version 2017/12/16
 */
@Api(tags = "用户管理")
@RestController
public class SwaggerUserController {


    @ApiOperation("创建用户")
    @PostMapping("/users")
    public User create(@RequestBody User user) {
        return user;
    }

    @ApiOperation("用户详情")
    @GetMapping("/users/{id}")
    public User query(@PathVariable Long id) {
        return new User(id, "张三", 18, "zhangsan@163.com");
    }

    @ApiOperation("分页查询用户")
    @GetMapping("/users")
    public List<User> list(@ApiParam("页码") @RequestParam int pageno,
                           @ApiParam("页大小") @RequestParam int pagesize) {
        ArrayList<User> users = new ArrayList<>();
        users.add(new User(1L, "张三", 18, "zhangsan@163.com"));
        users.add(new User(2L, "李四", 20, "lisi@163.com"));
        return users;
    }

    @ApiOperation("删除用户信息")
    @DeleteMapping("/users/{id}")
    public String delete(@PathVariable Long id) {
        return "delete user: " + id;
    }

}